package com.study.second_kill.server.service.impl;

import com.study.second_kill.model.entity.ItemKill;
import com.study.second_kill.model.mapper.ItemKillMapper;
import com.study.second_kill.server.service.IItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author xiongmin
 * @Description //TODO
 * @Date 2020/4/19 18:08
 * @Version 1.0
 **/
@Service
public class ItemService implements IItemService {

    @Autowired
    ItemKillMapper itemKillMapper;

    /**
     * 获取带秒杀商品列表
     * @return
     */
    @Override
    public List<ItemKill> getKillItems() {
        return itemKillMapper.selectAll();
    }

    @Override
    public ItemKill getKillDetail(Integer id) throws Exception {
        ItemKill itemKill = itemKillMapper.selectById(id);
        if (itemKill == null) {
            throw new Exception("获取秒杀详情-待秒杀商品记录不存在");
        }
        return itemKill;
    }
}
